/* internal/js/dialog.js */

function openModalDialog (title, htmlContents) {
	//this will only exer create one dialog, others will be sluffed
	var exist = document.getElementById('modalBackground');
	if (!exist) {
		var dialogBackground = document.createElement('div');
		dialogBackground.className = 'modalBackground';
		dialogBackground.setAttribute('id', 'modalBackground');
		var dialogBox = document.createElement('div');
		dialogBox.className = 'dialogBox';
		dialogBox.setAttribute('id', 'dialogBox');
		// create contents of the dialog box
		var dialogBoxContents = '';
		dialogBoxContents += '<table width="100%"><tr>';
		dialogBoxContents += '<td width="100%"><h2><font color="red">' + title + '</font></h2></td>';
		dialogBoxContents += '<td><strong><a href="#" onclick="closeModalDialog();return false">x</a></strong></td>';
		dialogBoxContents += '</tr>';
		dialogBoxContents += '<tr>';
		dialogBoxContents += '<td>' + htmlContents + '</td>';
		dialogBoxContents += '<tr><td class="alignCenter"><form><h2><a href="#" onclick="closeModalDialog();return false" value="OK">OK</h2>';
		dialogBoxContents += '</form></td>';
		dialogBoxContents += '</tr></table>';
		dialogBoxContents += '<br><br>';
		
		
		dialogBox.innerHTML = dialogBoxContents;
		
		document.body.appendChild(dialogBox);
		document.body.appendChild(dialogBackground);
	}
}

function closeModalDialog (response) {
	document.body.removeChild(document.getElementById('modalBackground'));
	document.body.removeChild(document.getElementById('dialogBox'));
}


function openConfirmModalDialog (title, htmlContents, confirmedAction) {
	//this will only exer create one dialog, others will be sluffed
	var exist = document.getElementById('modalBackground');
	if (!exist) {
		var dialogBackground = document.createElement('div');
		dialogBackground.className = 'modalBackground';
		dialogBackground.setAttribute('id', 'modalBackground');
		var dialogBox = document.createElement('div');
		dialogBox.className = 'dialogBox';
		dialogBox.setAttribute('id', 'dialogBox');
		// create contents of the dialog box
		var dialogBoxContents = '';
		dialogBoxContents += '<table width="100%"><tr>';
		dialogBoxContents += '<td width="100%"><h2>' + title + '</h2></td>';
		dialogBoxContents += '<td><strong><a href="#" onclick="closeModalDialog();return false">x</a></strong></td>';
		dialogBoxContents += '</tr>';
		dialogBoxContents += '<tr>';
		dialogBoxContents += '<td>' + htmlContents + '</td><tr>';
		dialogBoxContents += '<tr><td></td></tr>';
		dialogBoxContents += '<tr><td></td></tr>';
		dialogBoxContents += '</tr></table>';
		dialogBoxContents += '<br><br>';
		
		dialogBoxContents += '<table><tr><td align="center" width="100%">' + 
								'<a href="#" onclick="closeModalDialog(true);return false, ' +
			    				confirmedAction + '()" /><h2>OK</h2></a></td>';
		dialogBoxContents += '<td align="center" width="100%"><a href="#" onclick="closeModalDialog(false);return false"' +
							' value="Cancel"/><h2>Cancel</h2></a>';
		dialogBoxContents += '</td><td></td></tr></table>';
		
		
		dialogBox.innerHTML = dialogBoxContents;
		
		document.body.appendChild(dialogBox);
		document.body.appendChild(dialogBackground);
	}
}